Skip to content

Develop#322

Open
mForkosh wants to merge 4 commits intomate-academy:masterfrom
mForkosh:develop
Open

Develop#322
mForkosh wants to merge 4 commits intomate-academy:masterfrom
mForkosh:develop

Conversation

@mForkosh
Copy link

@mForkosh mForkosh commented Sep 6, 2025

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Decision: REQUEST_CHANGES — Several critical, blocking requirements are missing in src/app.js, which can lead to incorrect behavior and failing tests.

Critical issues to fix (with suggestions):

  1. Argument validation (exactly two args)

    • Where: src/app.js, near the CLI arg parsing (top of file, around where process.argv.slice(2) is used).
    • Why: Requirement says the app must verify exactly two positional arguments (source, destination) and throw if not.
    • How: Check args.length !== 2 and throw an Error like new Error('Usage: node index <source> <destination>'). Ensure process exits non‑zero.
  2. Source exists and is a file (not a directory)

    • Where: Before attempting fs.renameSync (same file, after parsing args).
    • Why: Must throw if source does not exist or is not a file; directories are not supported.
    • How: Use fs.existsSync(source) and fs.statSync(source).isFile(). If false, throw: new Error('Source must exist and be a file').
  3. Disallow moving directories (explicit check)

    • Where: Together with source validation.
    • Why: Requirement: only files supported; directories must error.
    • How: If fs.statSync(source).isDirectory(), throw an error.
  4. Destination ending with slash must refer to an existing directory

    • Where: When interpreting destination.
    • Why: If destination ends with / but that directory does not exist, you must throw and NOT create it.
    • How: If destPath.endsWith(path.sep), then verify fs.existsSync(destPath) and fs.statSync(destPath).isDirectory(). If not, throw.
  5. Parent directory existence for file destination

    • Where: Before renameSync when destination is treated as a file path (no trailing slash).
    • Why: Requirement says do not create directories; parent must exist.
    • How: Compute const parent = path.dirname(destPath); if not fs.existsSync(parent) or not a directory, throw.
  6. Proper error signaling

    • Where: All error paths and the main entry point.
    • Why: Errors must be thrown and process should exit non‑zero; logging alone is insufficient.
    • How: Wrap main in try/catch; on catch, console.error(err.message) (optional), then process.exit(1). Avoid swallowing errors.

Minor improvements (non-blocking):

  • Add small inline comments explaining the directory-vs-file decision logic.

You’ve got a solid starting point with concise use of fs.renameSync and no output on success. Address the above validations and error handling to fully meet the spec. You’re close—once these checks are in place, the app should behave correctly across the required edge cases.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

const fsCb = require('fs');
const path = require('path');

const [subject, destination] = process.argv.slice(2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no validation for the number of arguments. The requirements specify that you must verify exactly two arguments are provided (source and destination), and throw an error if not. Please add this validation.

src/app.js Outdated
let destinationIsDirectory = false;

try {
fileName = path.basename(subject);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no check to verify that the source path exists and is a file (not a directory). The requirements specify that you must throw an error if the source does not exist or is not a file. Please add this validation before proceeding.


try {
fileName = path.basename(subject);
destinationIsDirectory = fsCb.statSync(destination).isDirectory();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not handle the case where the destination ends with a slash (/) but does not exist. According to the requirements, if the destination is intended as a directory (ends with /) but does not exist, the app must throw an error and not create directories. Please add this check.

try {
fsCb.renameSync(subject, correctDestination);
} catch (err) {
console.error(err);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors are only logged to the console, but the requirements specify that errors must be thrown and the process should indicate failure (e.g., exit with a non-zero code). Please update error handling to throw errors and exit with a non-zero code on failure.

: destination;

try {
fsCb.renameSync(subject, correctDestination);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no explicit check to ensure that only files are supported (not directories). The requirements specify that the app must not support moving directories. Please add a check to ensure the source is a file and not a directory, and throw an error otherwise.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Decision: REQUEST_CHANGES

Your CLI logic is solid and aligns well with the requirements for argument parsing, file vs. directory handling, and using fs.renameSync. However, there is one critical blocker: all error paths currently exit with code 0, which violates the requirement that errors must exit with a non-zero status.

Critical issues to fix (blockers):

  • Incorrect error exit codes in src/app.js:
    • At each error path (e.g., invalid argument count, missing source, source is a directory, destination with trailing slash that doesn’t exist), you call process.exit(0). This signals success, which is incorrect for errors.
    • Requirement: errors must exit non-zero. Use process.exit(1) instead.
    • How to fix: replace each process.exit(0) in error branches with process.exit(1). For example:
      • When argument count is not exactly two (near the top where you validate process.argv), change to process.exit(1).
      • When the source does not exist or is a directory (the fs.statSync/isDirectory() checks), change to process.exit(1).
      • When destination ends with / but directory does not exist, change to process.exit(1).
      • Any other catch-all error paths should likewise use a non-zero exit code.

Minor (optional) improvements:

  • Make error messages a bit more descriptive (e.g., include the offending path). Not required, but improves UX.

Once you update the exit codes, the implementation should fully meet the requirements. You’re very close—nice work on the overall logic!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

if (process.argv.slice(2).length !== 2) {
console.error('Usage: node index <source> <destination>');

process.exit(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All error exits in this file use process.exit(0), which signals success. According to the requirements, error conditions (such as invalid arguments, missing files, or invalid destination) must exit with a non-zero code (e.g., process.exit(1)). Please change all process.exit(0) calls in error paths to process.exit(1) to properly signal errors as required.

if (!destinationIsDirectory && destination.endsWith(path.sep)) {
console.error('Destination must be correct path');

process.exit(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: this error exit should use process.exit(1) to indicate an error, not process.exit(0).


if (fsCb.statSync(subject).isDirectory()) {
console.error('Subject must be a file');
process.exit(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: this error exit should use process.exit(1) to indicate an error, not process.exit(0).

}
} catch (subError) {
console.error(`subject doesn't exist`);
process.exit(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: this error exit should use process.exit(1) to indicate an error, not process.exit(0).

Copy link

@vitalii-bondarenko-ua vitalii-bondarenko-ua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants